import type { GetParkSysUserData, Role, RoleDetailData, RoleDetail, RoleUserData, RoleParams, GetParkSysData } from "@/types/system"
import { request } from "./reuqest"
import type { PageParams } from "@/types/common"


/**
 * 获取角色列表
 * @returns
 */
export const getRoleListAPI = () => {
  return request<Role[]>('/park/sys/role')
}


// 系统管理-角色管理-查询所有功能权限(树形)

export const  GetParkSysPermissionAllTreeAPI = () => {
  return request<RoleDetailData[]>('/park/sys/permision/all/tree','GET')
}

/**
 * 查询当前角色详情-权限和分配人数
 * @returns
 */
export const getRoleDetailAPI = (roleId: number) =>{
  return request<RoleDetail>(`/park/sys/role/${roleId}`)
}


/**
 * 获取角色成员列表
 * @param roleId 角色id
 * @param params 分页参数
 * @returns 
 */
export const getRoleUserAPI = (roleId: number, params?: PageParams) => {
  return request<RoleUserData>(`/park/sys/roleUser/${roleId}`, 'GET', params)
}


/**
 * 角色管理-添加角色
 * @param data 
 * @returns 
 */
export const createRoleUserAPI = (data: RoleParams) => {
  return request('/park/sys/role', 'POST', data)
}

// 获取角色详情 
export const getParkSysDataAPI = (roleId: number) => {
  return request<GetParkSysData>(`/park/sys/role/${roleId}`)
}

/**
 * 角色管理-修改角色
 * @param data 
 * @returns
 */
export const updateRoleUserAPI = (data: RoleParams) => {
  return request('/park/sys/role', 'PUT', data)
}


// 删除用户
export const deleteUserAPI = (id: string) => {
  return request(`/park/sys/role/${id}`, 'DELETE')
}

